package com.wqz.utils;

import com.wqz.dao.UserDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class MyBatisUtil {

    private static SqlSessionFactory factory;

    static {
        try {

            InputStream is = Resources.getResourceAsStream("mybatis.xml");
            factory = new SqlSessionFactoryBuilder().build(is);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static SqlSession createSqlSession() {
        return factory.openSession(true);
    }

    public static void close(SqlSession sqlSession) {
        if(null != sqlSession) {
            sqlSession.close();
        }
    }


}
